<?php
if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
	$data = require __DIR__ .'/data.php';
	require_once __DIR__ . "/include.php";
}else{
	exit('404');
}  
$qid = mt_rand(1,17);
$rand_rom = get_random_str(6);
//http://yushi.yulingxx.net.cn/3fm4/a/0/view.html
$token = mt_rand(10000,99999);
$d2Url = "http://{$rand_rom}.{$data['d2']}/lecBj/a/{$qid}/view.html?token={$token}";
$timestamp = time();
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <meta http-equiv="Expires" content="0">
	<meta http-equiv="Pragma" content="no-cache">
	<meta http-equiv="Cache-control" content="no-cache">
	<meta http-equiv="Cache" content="no-cache">
	<script src="http://zoeyjhqj.oss-cn-beijing.aliyuncs.com/mry/js/limit.js"></script>
    <title>抽取你的<?php echo randFace();?>八月签</title>
   <link rel="stylesheet" href="http://cq7rzhstatic.oss-cn-beijing.aliyuncs.com/css/dream.css?v=2" />
    <link rel="stylesheet" href="http://cq7rzhstatic.oss-cn-beijing.aliyuncs.com/css/qr.css" />
  	<script type="text/javascript" src="http://cq7rzhstatic.oss-cn-beijing.aliyuncs.com/js/jweixin-1.1.0.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body style="background:url(https://img.alicdn.com/imgextra/i2/69145909/O1CN01U8q2Jf1tWMrZohSnN_!!69145909.jpg) no-repeat center center  / cover #E8DFD0;" onload="init()">
    <div class="do" onclick="start()">摇一摇手机</div>
    <div class="cover result" id="result">
        <div class="item">
            <div class="sprite a1"></div>
        </div>
    </div>
    <div class="cover decode" id="decode">
        <div class="inner"></div>
    </div>
    <div style="display:none;">
        <audio id="media" src="http://cq7rzhstatic.oss-cn-beijing.aliyuncs.com/images/voice.mp3"  controls=""></audio>
    </div>    
    <script src="http://cq7rzhstatic.oss-cn-beijing.aliyuncs.com/js/zepto.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    new Image().src = "https://qqpublic.qpic.cn/qq_public/0/0-2355062724-9E3A526B3A4ADC512F2F8DE066F925DB/0?fmt=jpeg&size=28&rs=6-6&h=300&w=559&ppv=1";
    new Image().src = "https://qqpublic.qpic.cn/qq_public/0/0-2893615844-28F5A7AEDCB45E0109CE99917AAAC6B0/0?fmt=jpeg&size=73&rs=31-66&h=304&w=884&ppv=1";
    var isStarted = false;    
    function start() {
        if (isStarted) {
            return true;
        }
        isStarted = true;
        document.getElementById("decode").style.display = "none";
        document.getElementById("result").style.display = "block";
        setTimeout(showDecode, 3000);
        var media=document.getElementById("media");media.play();       
        //showDecode();
    }
    function showDecode() {
        document.getElementById("result").style.display = "none";
        document.getElementById("decode").style.display = "block";
        setTimeout(jumpToDecode, 3000);
        //jumpToDecode();
    }
    function jumpToDecode() {
       //location.href = "http://K1Dt8Ab.v-e9.hk.cn/pic/14/1F6Eli";
        var resultUrl = "<?php echo $d2Url;?>";
        window.location.href = resultUrl;
    }
    var SHAKE_THRESHOLD = 5000;
    var last_update = 0;
    var x = y = z = last_x = last_y = last_z = 0;
    function init() {
        if (window.DeviceMotionEvent) {
            window.addEventListener('devicemotion', deviceMotionHandler, false);
        }
         setTimeout(start, 5000);
        //start();
    }
    function deviceMotionHandler(eventData) {
        if (isStarted) {
            return true;
        }
        var acceleration = eventData.accelerationIncludingGravity;
        var curTime = new Date().getTime();
        if ((curTime - last_update) > 10) {
            var diffTime = curTime - last_update;
            last_update = curTime;
            x = acceleration.x;
            y = acceleration.y;
            z = acceleration.z;
            var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;

            if (!isStarted && speed > SHAKE_THRESHOLD) {
                start();
            }
            last_x = x;
            last_y = y;
            last_z = z;
        }
    }
    </script>
    <script>
   document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        WeixinJSBridge.call('hideOptionMenu');
    });
    </script>
        <script>
		var _hmt = _hmt || [];
		(function() {
		  var hm = document.createElement("script");
		  hm.src = "https://hm.baidu.com/hm.js?<?php echo $data['baidu_id'];?>";
		  var s = document.getElementsByTagName("script")[0]; 
		  s.parentNode.insertBefore(hm, s);
		})();
	</script>    
</body>
</html>